package com.system.demo.tool;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 包含 count 和 data 的数据
     */
    private ResponseData<T> data;

    // 内部类，用于封装 count 和 data
    public static class ResponseData<T> {
        private long count;
        private T data;

        public ResponseData(long count, T data) {
            this.count = count;
            this.data = data;
        }

        public long getCount() {
            return count;
        }

        public void setCount(long count) {
            this.count = count;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }
    }

    // 构造方法
    public ResponseResult(Integer code, String msg, ResponseData<T> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = new ResponseData<>(0, null); // 默认 data 字段，count=0, data=null
    }

    // 成功静态方法
    public static <T> ResponseResult<T> success(String msg, long count, T data) {
        return new ResponseResult<>(200, msg, new ResponseData<>(count, data));
    }

    public static <T> ResponseResult<T> success(String msg, T data) {
        return new ResponseResult<>(200, msg, new ResponseData<>(0, data));
    }

    public static <T> ResponseResult<T> success(String msg) {
        return new ResponseResult<>(200, msg);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(200, "success");
    }

    // 错误静态方法
    public static <T> ResponseResult<T> BadRequest(String msg) {
        return new ResponseResult<>(400, msg);
    }

    public static <T> ResponseResult<T> BadRequest() {
        return new ResponseResult<>(400, "BadRequest");
    }

    public static <T> ResponseResult<T> Unauthorized(String msg) {
        return new ResponseResult<>(401, msg);
    }

    public static <T> ResponseResult<T> Unauthorized() {
        return new ResponseResult<>(401, "Unauthorized");
    }

    public static <T> ResponseResult<T> Forbidden(String msg) {
        return new ResponseResult<>(403, msg);
    }

    public static <T> ResponseResult<T> Forbidden() {
        return new ResponseResult<>(403, "Forbidden");
    }

    public static <T> ResponseResult<T> NotFound(String msg) {
        return new ResponseResult<>(404, msg);
    }

    public static <T> ResponseResult<T> NotFound() {
        return new ResponseResult<>(404, "Not Found");
    }

    public static <T> ResponseResult<T> Conflict(String msg) {
        return new ResponseResult<>(409, msg);
    }

    public static <T> ResponseResult<T> Conflict() {
        return new ResponseResult<>(409,"Conflict");
    }

    public static <T> ResponseResult<T> InternalServerError(String msg) {
        return new ResponseResult<>(500, msg);
    }

    public static <T> ResponseResult<T> InternalServerError() {
        return new ResponseResult<>(500, "Internal Server Error");
    }

    // Getters 和 Setters
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public ResponseData<T> getData() {
        return data;
    }

    public void setData(ResponseData<T> data) {
        this.data = data;
    }
}